home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcombo.exe / TCMBOVWR.CPP < prev    next >
C/C++ Source or Header  |  1992-11-18  |  4KB  |  154 lines

  1. /*************************************************************************/
  2. /*                                                                       */
  3. /* TCMBOVWR.CPP                                                          */
  4. /*                                                                       */
  5. /* Copyright (c) 1992, Vincent J. Dentice                                */
  6. /* All rights reserved                                                   */
  7. /*                                                                       */
  8. /* The TComboBox class is an extension to Borland International's Turbo  */
  9. /* Vision Applications Framework for DOS.  It provides a class that      */
  10. /* acts like a Combo Box in other graphical environments like Microsoft  */
  11. /* Windows and IBM OS/2.                                                 */
  12. /*                                                                       */
  13. /* It is designed to be with a TDialog class and a TCollection Class.    */
  14. /*                                                                       */
  15. /*                                                                       */
  16. /*   Date    Prg  Ver  Description                                       */
  17. /* --------  ---  ---  ------------------------------------------------- */
  18. /* 09/30/92  VJD  0.1  Initial module definition.                        */
  19. /* 11/16/92  VJD  0.2  Added streamability to the TComboBox classes.     */
  20. /*                     Rewrote header files to behave like original      */
  21. /*                     Turbo Vision header files.                        */
  22. /* 11/17/92  VJD  0.3  Added the missing dataSize function to            */
  23. /*                     TComboViewer.                                     */
  24. /*                                                                       */
  25. /*************************************************************************/
  26.  
  27. #define Uses_TComboViewer
  28. #define Uses_TKeys
  29. #define Uses_TStreamableClass
  30. #include "tcombobx.h"
  31. #include <string.h>
  32.  
  33. #define cpComboViewer "\x06\x06\x07\x06\x06"
  34.  
  35. struct TComboViewerRec
  36. {
  37.     TCollection *items;
  38.     ushort selection;
  39. };
  40.  
  41.  
  42. TComboViewer::TComboViewer(const TRect& bounds, TCollection *aList, TScrollBar *ts) :
  43.           TListViewer(bounds, 1, 0, ts)
  44. {
  45.    list = 0;
  46.    newList(aList);
  47. }
  48.  
  49.  
  50. ushort TComboViewer::dataSize()
  51. {
  52.    return sizeof(TComboViewerRec);
  53. }
  54.  
  55.  
  56. TPalette& TComboViewer::getPalette() const
  57. {
  58.    static TPalette palette(cpComboViewer, sizeof(cpComboViewer)-1);
  59.    return palette;
  60. }
  61.  
  62.  
  63. void TComboViewer::getData( void * rec )
  64. {
  65.     TComboViewerRec *p = (TComboViewerRec *)rec;
  66.  
  67.     p->items = list;
  68.     p->selection = focused;
  69. }
  70.  
  71.  
  72. void TComboViewer::getText(char *dest, short item, short maxLen)
  73. {
  74.    if (list != 0 ) {
  75.       strncpy( dest, (const char *)(list->at(item)), maxLen );
  76.       dest[maxLen] = '\0';
  77.    }
  78.    else
  79.       *dest = EOS;
  80. }
  81.  
  82.  
  83. void TComboViewer::handleEvent(TEvent& event)
  84. {
  85.    if ((event.what == evMouseDown && event.mouse.doubleClick) ||
  86.        (event.what == evKeyDown && event.keyDown.keyCode == kbEnter))
  87.    {
  88.       endModal(cmOK);
  89.       clearEvent(event);
  90.    }
  91.    else    if ((event.what ==  evKeyDown && event.keyDown.keyCode == kbEsc) ||
  92.         (event.what ==  evCommand && event.message.command ==  cmCancel))
  93.    {
  94.       endModal(cmCancel);
  95.       clearEvent(event);
  96.    }
  97.    else
  98.       TListViewer::handleEvent(event);
  99. }
  100.  
  101.  
  102. void TComboViewer::newList( TCollection *aList )
  103. {
  104.    if (list)
  105.       destroy(list);
  106.    list = aList;
  107.    if(aList != 0)
  108.       setRange(aList->getCount());
  109.    else
  110.       setRange(0);
  111.    if(range > 0)
  112.       focusItem(0);
  113.    drawView();
  114. }
  115.  
  116.  
  117. void TComboViewer::setData( void *rec )
  118. {
  119.     TComboViewerRec *p = (TComboViewerRec *)rec;
  120.     newList(p->items);
  121.     focusItem(p->selection);
  122.     drawView();
  123. }
  124.  
  125.  
  126. void TComboViewer::shutDown()
  127. {
  128.    list = 0;
  129.    TListViewer::shutDown();
  130. }
  131.  
  132.  
  133. void * TComboViewer::read( ipstream& is )
  134. {
  135.    TListViewer::read(is);
  136.    is >> list;
  137.    return this;
  138. }
  139.  
  140. void TComboViewer::write( opstream& os )
  141. {
  142.    TListViewer::write(os);
  143.    os << list;
  144. }
  145.  
  146.  
  147. TStreamable *TComboViewer::build()
  148. {
  149.    return new TComboViewer(streamableInit);
  150. }
  151.  
  152.  
  153. TComboViewer::TComboViewer(StreamableInit) : TListViewer(streamableInit) { }
  154.